﻿using System;
using System.Collections.Generic;
using NOSDC.Pocos;
using System.Web.Mvc;

namespace NOSDC.Areas.Admin.Models
{
    public class EventsCreateViewModel
    {
        private IList<Sponsor> _sponsor;
        private IList<Speaker> _speaker;

        public Events Events { get; set; }
        public IEnumerable<SelectListItem> StatusValues { get; set; }
        public IEnumerable<SelectListItem> Logos { get; set; }
        public IList<CheckBoxList> SponsorCheckList { get; private set; }
        public IList<CheckBoxList> SpeakerCheckList { get; private set; }
        public IList<Speaker> Speaker
        {
            get { return _speaker; }
            set
            {
                _speaker = value;
                CreateSpeakerList(value);
            }
        }

        public IList<Sponsor> Sponsor
        {
            get { return _sponsor; }
            set
            {
                _sponsor = value;
                CreateCheckList(value);
            }
        }

        /// <summary>
        /// Creates the sponsor checklist
        /// </summary>
        /// <param name="sponsors">A list of checkbox items</param>
        private void CreateCheckList(IEnumerable<Sponsor> sponsors)
        {
            foreach (var s in sponsors)
            {
                SponsorCheckList.Add(new CheckBoxList { Checked=Events.Sponsors.Exists(sp =>  sp.SponsorId == s.SponsorId), ID = s.SponsorId, Name = s.Name });
            }
        }

        /// <summary>
        /// Creates the sponsor checklist
        /// </summary>
        private void CreateSpeakerList(IEnumerable<Speaker> speakers)
        {
            foreach (var s in speakers)
            {
                SpeakerCheckList.Add(new CheckBoxList { Checked = Events.Speakers.Exists(sp => sp.SpeakerId == s.SpeakerId), ID = s.SpeakerId, Name = s.ToString() });
            }
        }

        public EventsCreateViewModel()
        {
            Events = new Events
            {
                StartDate = DateTime.Now,
                EndDate = DateTime.Now
            };

            Sponsor = new List<Sponsor>();
            SponsorCheckList = new List<CheckBoxList>();
            SpeakerCheckList = new List<CheckBoxList>();
            StatusValues = new List<SelectListItem>
            {
                new SelectListItem{
                    Text = "Active",
                    Value= "1",
                    Selected = true
                },
                   new SelectListItem{
                    Text = "Inactive",
                    Value= "2",
                    Selected = false
                }
            };

            Logos = CreateLogoDropdown();
        }


        public static IEnumerable<SelectListItem> CreateLogoDropdown()
        {
            IEnumerable<SelectListItem> items = new List<SelectListItem>
              {
                new SelectListItem{
                    Text = "-- No Logo --",
                    Value = "",
                    Selected = true
                },
                    new SelectListItem{
                    Text = "Windows 7",
                    Value= "win7.png",
                    Selected = false
                },
                   new SelectListItem{
                    Text = "Windows Phone 7",
                    Value= "wp7.png",
                    Selected = false
                },
                new SelectListItem{
                    Text = "C#",
                    Value= "c#.png",
                    Selected = false
                },
                   new SelectListItem{
                    Text = "ASP.Net",
                    Value= "aspnet32.jpg",
                    Selected = false
                },
                   new SelectListItem{
                    Text = "Silverlight",
                    Value= "silverlight.png",
                    Selected = false
                },
                   new SelectListItem{
                    Text = "WPF",
                    Value= "wpf.png",
                    Selected = false
                },
                   new SelectListItem{
                    Text = "SQL",
                    Value= "sql.png",
                    Selected = false
                },
                   new SelectListItem{
                    Text = "Design Strategies",
                    Value= "ds.jpg",
                    Selected = false
                },
                   new SelectListItem{
                    Text = "VB.Net",
                    Value= "vb.jpg",
                    Selected = false
                },
                new SelectListItem{
                    Text = "Black Berry",
                    Value = "bb.png",
                    Selected = false
                },
                     new SelectListItem{
                    Text = "Android",
                    Value = "android-logo30x30.png",
                    Selected = false
                }
            };

            return items;
        }

    }

    public sealed class CheckBoxList
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public bool Checked { get; set; }
    }
}
